/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
// 二分查找要注意的就是边界
var searchInsert = function(nums, target) {
  let left = 0, right = nums.length - 1
    let ans = 0
    while(left <= right) {
      let mid = (left + right) >> 1
      if(nums[mid] == target) return mid
      else if(nums[mid] < target) {
        left = mid + 1
      } else {
        right = mid - 1
      }
    }
    return left
  };